import Router from '@koa/router'
import * as ins from './appiumInstagram.cjs'
import {success, fail, checkParams} from './commonApi.cjs'

const env = 'dev'

// 创建一个路由
const makeRoute = () => {
    const router = new Router()
    // 创建一个浏览器实例
    router.post('/createInstagramClient', async (ctx, next) => {
        ins.createInstagramClient()
        success(ctx)
    });
    router.post('/closeInstagramClient', async (ctx, next) => {
        ins.closeInstagramClient()
        success(ctx)
    });

    router.post('/autoPost', async (ctx, next) => {
        ins.autoPost()
        success(ctx)
    });

    router.post('/autoFollow', async (ctx, next) => {
        ins.autoFollow()
        success(ctx)
    });

    router.post('/testMove', async (ctx, next) => {
        ins.testMove()
        success(ctx)
    });
    
    
    return router
}

export function init(app) {
    const router = makeRoute()

    app.use(checkParams)
    app.use(router.routes()).use(router.allowedMethods())
}
